package top.andnux.weather.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.viewholder.QuickViewHolder;

import java.io.File;

import top.andnux.weather.R;
import top.andnux.weather.activity.PicturePreviewActivity;

public class PhotoAdapter extends BaseQuickAdapter<String, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder quickViewHolder, int i,
                                    @Nullable String file) {
        ImageView imageView = quickViewHolder.getView(R.id.img1);
        Context context = imageView.getContext();
        Glide.with(context)
                .load(new File(file)).skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
        imageView.setOnClickListener(v -> PicturePreviewActivity.start(imageView.getContext(), file));
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_image, viewGroup, false);
        return new QuickViewHolder(view);
    }
}
